import json
import os
import gzip

id = 0
with open("cpptrait.jsonl", "w") as f:
    for dir in os.listdir():
        data = {}
        if os.path.isdir(os.path.join(".", dir)):
            data["name"] = dir
            data["id"] = id
            for file in os.listdir(os.path.join(".", dir)):
                file_name = file.split(".")[0]
                with open(os.path.join(".", dir, file), "r") as inner_f:
                    data[file_name] = inner_f.read()
            id += 1
            f.write(json.dumps(data) + "\n")
            
with open("cpptrait.jsonl", "rb") as f:
    gz_file = gzip.GzipFile(filename="cpptrait.jsonl", mode="wb", compresslevel=9, fileobj=open("cpptrait.jsonl.gz", "wb"))
    gz_file.write(f.read())
    gz_file.close()        
    